//
//  BaseTableViewController.m
//  RedManStock
//
//  Created by lanou3g on 15/7/19.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()



@end

@implementation BaseTableViewController


- (instancetype)initWithHeader:(BOOL)HeaderOrNot
                        footer:(BOOL)footerOrNot{
    if (self=[super init]) {
        
        self.headerOrNot=HeaderOrNot;
        self.footerOrNot=footerOrNot;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view=[[UIView alloc]initWithFrame:CGRectZero];
    self.tableView.tableFooterView=view;
    
    //设置刷新头或刷新尾
    if (self.headerOrNot) {
        MJRefreshGifHeader *header=[MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
        
//        NSMutableArray *idleArray=[NSMutableArray array];
        NSMutableArray *pullingArray=[NSMutableArray array];
        NSMutableArray *refreshArray=[NSMutableArray array];
        NSMutableArray *doneArray=[NSMutableArray array];
        
//        for (int i=0; i<=140; i++) {
//            NSString *placeStr=[NSString string];
//            if (i<10) {
//                placeStr=[NSString stringWithFormat:@"00%d",i];
//            }
//            else if(i>=10 && i<100){
//                placeStr=[NSString stringWithFormat:@"0%d",i];
//            }
//            else{
//                placeStr=[NSString stringWithFormat:@"%d",i];
//            }
//            
//            NSString *imageName=[NSString stringWithFormat:@"PullToRefresh_%@",placeStr];
//            UIImage *image=[UIImage imageNamed:imageName];
//            if (i<=73) {
//                [pullingArray addObject:image];
//            }
//            else if(i>73 && i<=127){
//                [refreshArray addObject:image];
//            }
//            else{
//                [doneArray addObject:image];
//            }
//            
//        }
//        for (int i=1; i<15; i++) {
//            UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"pre%d@2x",i]];
//            [pullingArray addObject:image];
//        }
        
        
        for (int i=0; i<6; i++) {
            UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"RefreshUp_%d@2x",i]];
            [pullingArray addObject:image];
        }
        
        [header setImages:pullingArray forState:MJRefreshStatePulling];
        [header setImages:pullingArray forState:MJRefreshStateRefreshing];
        [header setImages:pullingArray forState:MJRefreshStateNoMoreData];
        
        header.lastUpdatedTimeLabel.hidden=YES;
        header.stateLabel.hidden=YES;
        
        self.tableView.header=header;
        
    }
    if (self.footerOrNot) {
        self.tableView.footer=[MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        
    }
    self.clearsSelectionOnViewWillAppear=YES;
    
}


//- (void)viewWillAppear:(BOOL)animated{
//    
//}

- (void)loadNewData{
    //留作子类实现
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        // 结束刷新
//        [self.tableView.header endRefreshing];
//    });
    
}

- (void)loadMoreData{
    //子类实现
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        // 结束刷新
//        [self.tableView.footer endRefreshing];
//    });
}

- (void)dataSourceWithJasonDic:(NSDictionary *)requestDic{
    //子类实现
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
//    // Return the number of sections.
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
//    // Return the number of rows in the section.
//    return 0;
//}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
